package com.entersoft.sicep.log4j;

import java.io.File;

/**
 * Package: log4j
 * Clase: UtilLog4J
 * Descripción: Ubicación de propertiess
 * Versión SICEP: 3.0
 * Autor: Cesar Pino - Entersoft
 * fecha creación: xx/xx/2012
 * ----------------------------------
 * 
 * Modificado por: XXXXXXXXXXXXXXXXXX
 * Motivo de actualización: XXXXXXXXX
 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 * fecha actualización: xx/xx/2012
 */
public final class UtilLog4J {
    private static UtilLog4J me = null;
    private static String PROP_LOG4J = "wapps_sicep_log4j.properties";
    //private static final String LOGS_PROPERTIES = "C:/dataSicep/properties/wapps_sicep_log4j.properties";
    private static final String LOGS_PROPERTIES = "D:/QA/dataSicep/properties/wapps_sicep_log4j.properties";


    private UtilLog4J() throws Exception{
            try {

                    File f = PropertiesUtil.findFile( PROP_LOG4J );
                    if( f!=null && f.exists() && f.isFile() ){

                       org.apache.log4j.PropertyConfigurator.configure(f.getAbsolutePath());

                    }
                    else{
                        org.apache.log4j.PropertyConfigurator.configure(LOGS_PROPERTIES);
                        //org.apache.log4j.PropertyConfigurator.configure(DEFAULT_PATH_PROP_LOG4J + "/" + PROP_LOG4J);
                    }
                    Log4jUtil.instance().info(this.getClass(), "Log4J Iniciado en WAPPS_Sicep ...");
            }
            catch (Throwable t) {
                    Log4jUtil.instance().error(this.getClass(), t,t);
                    throw new Exception("Exception al cargar log4j en UtilLog4J"+ t.getMessage()+ t);
            }
    }

    public static UtilLog4J getInstance() throws Exception{
            synchronized(UtilLog4J.class){
                    if(me == null){
                            me = new UtilLog4J();
                    }
                    return me;
            }
    }

}
